<template>
  <div>
    <div class="search-pad">
      <input type="text" name="" id="" @focus="searchFocus()" @blur="searchBlur()">
      <button v-show="isShowSearchBtn">搜索</button>
      <button v-show="!isShowSearchBtn" @click="showRight()">筛选</button>
    </div>
    <div class="system-pad">
      <div >     </div>
        <div v-for="belongType in belongTypes" :key="belongType.sysNo" :class="['system-item',{'system-select':systemIndex==belongType.belongTypeName}]"
             @click="getSystemProduct(belongType.belongTypeName)">
          <span>{{belongType.belongTypeName}}
          </span>
        </div>
    </div>
    </div>
    <div class="product-list">
      <ul>
        <li v-for="product in products" :key="Product"   v-show="!isShowSearchBtn" @click="showRight()">
          <img v-if="product.belongTypeName=='男'" src="/img/productPhotos/huge.png" alt="">
          <img v-if="product.belongTypeName=='女'" src="/img/productPhotos/liuyifei.png" alt="">
          <div>
            <p class="p-name">{{product.productName}}</p>
           <p class="p-type">身高：200CM，体重：100KG</p>

            <p class="p-price">&yen;80000/月，职业：职场办公桌试睡员</p>
          </div>
        </li>
      </ul>

      <div :class="['left-menu',{'left-menu-show':isShowLeft}]">
        <div class="left-switch" @click="showLeft()">
          <img src="/img/dealerImgs/up.png" alt="">
        </div>
        <ul>
          <li>免漆板背板</li>
          <li>免漆板</li>
          <li>面板</li>
          <li class="left-item-select">木工板</li>
          <li>木工板</li>
          <li>木工板</li>
          <li>免漆板背板</li>
          <li>免漆板</li>
          <li>面板</li>
          <li>木工板</li>
          <li>木工板</li>
          <li>木工板</li>
          <li>免漆板背板</li>
          <li>免漆板</li>
          <li>面板</li>
          <li>木工板</li>
          <li>木工板</li>
          <li>木工板</li>
        </ul>
      </div>
    </div>


    <div class="right-pad">
      <ul class="f-type-list">
        <li>
          <p>颜色</p>
          <div class="clear-tag"></div>
        </li >
        <img style=" width: 100%; height: 100%;"  src="/img/userPhotoItem/A001.png" alt="">
      </ul>
      <div class="right-edit">
        <button @click="hideRight()">返回</button>
      </div>
    </div>
    <div class="cover" v-show="isShowCover" @click="hideRight()"></div>
</template>

<script lang="ts">
import {onMounted, reactive, toRefs} from "vue";
import {getProduct,getBelongtype} from "../HttpRequests/ProductLIstRequest";
import {IProductInfo,IProduct,IBlongType} from "../interfaces/ProductList";
export default {
//setup在生命周期中处于哪个环节呢 处于create环节
setup(){
  const pageController = reactive({
    systemIndex : "1",
    isShowLeft : false,
    isShowCover : false,
    isShowSearchBtn : false
  })

  const productInfo:IProductInfo = reactive({
    products:[],
    belongTypes:[],
    getProducts:async (belongTypeName:string)=>{
      console.log(belongTypeName,'belong')
      productInfo.products = await getProduct({
        belongTypeName:belongTypeName,
        sort:"Id",
        pageIndex:1
      });
    },
    getBelongTypes:async()=>{
      productInfo.belongTypes = await getBelongtype() as IBlongType[];
    },
    getSystemProduct : (belongTypeName:string)=> {
      console.log(belongTypeName,'belong');
      pageController.systemIndex = belongTypeName;
      productInfo.getProducts(belongTypeName);
    }
  })


  const showLeft=()=> {
    pageController.isShowLeft = !pageController.isShowLeft;
  }
  const searchFocus=()=> {
    pageController.isShowSearchBtn = true;
  }
  const searchBlur=()=> {
    pageController.isShowSearchBtn = false;
  }
  const confirmFilter=()=> {
  }
  const showRight=()=> {
    pageController.isShowCover = true;
    document.querySelector(".right-pad").style.right = "0";
  }
  const hideRight=()=> {
    pageController.isShowCover= false;
    document.querySelector(".right-pad").style.right = "100%";
  }
  onMounted(async()=>{
    productInfo.getProducts("男");
    productInfo.getBelongTypes();
  })
  return {
    ...toRefs(pageController),
    ...toRefs(productInfo),
    showLeft,
    searchFocus,
    searchBlur,
    confirmFilter,
    showRight,
    hideRight
  }
},
  // data() {
  //   return {
  //     systemIndex: 1,
  //     isShowLeft: false,
  //     isShowCover: false,
  //     isShowSearchBtn: false,
  //   }
  // },
  mounted() {
  },
  methods: {

  }
}
</script>

<style lang="scss" scoped>
.i-search:after {
  background-color: #b70101 !important;
}

.search-pad {
  padding: 6px 20px;
  background-color: #f0f0f0;
  display: flex;

  input {
    height: 28px;
    box-sizing: border-box;
    border: 1px solid #ddd;
    border-radius: 3px;
    flex: 1;
    outline: none;
  }

  button {
    background-color: transparent;
    width: 56px;
    border: 0 none;
    font-size: 14px;
    font-weight: bold;
    color: #333;
    outline: none;
  }
}

.system-pad {
  background-color: #fff;
  display: flex;

  .system-item {
    flex: 1;
    text-align: center;
    border-bottom: 1px #ddd solid;
    border-right: 1px transparent solid;
    border-left: 1px transparent solid;

    span {
      border: 0 none !important;
      background-color: #f0f2f5;
      margin: 6px 5px;
      font-size: 12px;
      font-weight: normal;
      text-align: center;
      border-radius: 4px;
      padding: 6px 0;
      display: block;
      height: 32px;
      line-height: 32px;
    }

  }

  .system-select {
    border-bottom: 1px transparent solid;
    border-right: 1px #ddd solid;
    border-left: 1px #ddd solid;

    span {
      background-color: transparent;
    }
  }
}

.product-list {
  ul {
    background-color: #fff;

    li {
      list-style: none;
    ;
      height: 88px;
      padding-left: 108px;
      position: relative;

      img {
        height: 66px;
        width: 66px;
        background-color: #ccc;
        position: absolute;
        left: 28px;
        top: 11px;
      }

      div {
        padding: 10px 0;
        border-bottom: 1px solid #f0f0f0;
        padding-bottom: 12px;
        //text-align: left;
        .p-name {
          font-size: 13px;
        }

        .p-type {
          font-size: 12px;
          color: #666;
          margin-top: 8px;
        }

        .p-price {
          font-size: 13px;
          color: #f23030;
          margin-top: 8px;
        }
      }
    }
  }

  .left-menu {
    position: fixed;
    height: calc(100% - 116px);
    left: -106px;
    width: 125px;
    background-color: #fff;
    top: 76px;
    border-radius: 0 18px 0 0;
    border: 1px solid #d7d7d7;
    overflow: hidden;
    transition: 0.5s;
    margin-bottom: 120px;

    .left-switch {
      width: 20px;
      background-color: #fff;
      position: absolute;
      right: 0;
      height: 100%;

      img {
        position: absolute;
        top: 42%;
        left: 2px;
        width: 20px;
        transform: rotate(90deg);
        transition: 0.5s;
      }
    }

    ul {
      position: absolute;
      height: 100%;
      width: 106px;
      background-color: #f0f0f0;
      overflow: auto;

      li {
        width: 106px;
        height: 50px;
        text-align: center;
        line-height: 50px;
        border-bottom: 1px solid #d7d7d7;
        padding: 0;
        font-size: 12px;
        color: #333;
      }

      li.left-item-select {
        background-color: #fff;
      }
    }
  }

  .left-menu-show {
    left: 0;

    .left-switch {
      img {
        transform: rotate(-90deg);
      }
    }

  }
}

.right-pad {
  position: fixed;
  /* right: -85%; */
  right: -85%;
  top: 0;
  width: 85%;
  height: 100%;
  background-color: #f7f7f7;
  z-index: 103;
  transition: 580ms;
  z-index: 101;

  ul {
    list-style: none;
    overflow: hidden;
  }

  .f-type-list {
    overflow: hidden;

    >li {
      padding: 10px;
      background-color: #fff;
      margin-bottom: 10px;

      .f-item-list {
        overflow: hidden;
        display: flex;
        flex-wrap: wrap;

        li {
          flex-basis: 33.3%;

          span {
            display: block;
            margin-top: 10px;
            margin-right: 10px;
            background: #eee;
            border: 1px solid #eee;
            padding: 5px 0;
            text-align: center;
            border-radius: 6px;
            font-size: 13px;
          }

          .prop-select {
            border: 1px solid red;
            background: #fff;
            color: red;
          }
        }

      }

      p {
        font-size: 14px;
      }
    }
  }

  .right-edit {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;

    button {
      float: left;
      height: 40px;
      width: 100%;
      line-height: 40px;
      text-align: center;
      border: 0px none;
    }
  }
}

.cover {
  position: fixed;
  height: 100%;
  width: 100%;
  left: 0;
  top: 0;
  background-color: rgba(51, 51, 51, 0.36);
}
</style>
